package com.breeze.blockchain.controller.admin;

import com.breeze.blockchain.controller.admin.form.setting.SettingPageForm;
import com.breeze.blockchain.mybatis.entity.SettingDo;
import com.breeze.blockchain.service.SettingService;
import com.breeze.components.web.core.ResponseDTO;
import com.mybatisflex.core.paginate.Page;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import java.util.List;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 配置表 控制层。
 *
 * @author breeze
 * @since 2024-05-11 23:21:51
 */
@RestController
@Tag(name = "配置表接口")
@RequestMapping("api/admin/setting")
public class SettingController {

  @Resource private SettingService settingService;

  @PostMapping("saveOrUpdate")
  @Operation(summary = "配置新建或更新")
  public ResponseDTO<Void> addOrUpdate(@RequestBody SettingDo tySetting) {
    settingService.addOrUpdate(tySetting);
    return ResponseDTO.ok();
  }

  @GetMapping("/all")
  @Operation(summary = "全部配置")
  public ResponseDTO<List<SettingDo>> list() {
    return ResponseDTO.ok(settingService.queryChain().orderBy(SettingDo::getId).desc().list());
  }

  @PostMapping("page")
  @Operation(summary = "分页查询配置表")
  public ResponseDTO<Page<SettingDo>> page(@Parameter(name = "配置表") SettingPageForm request) {
    return ResponseDTO.ok(settingService.page(request.toPage(), request.toQueryWrapper()));
  }
}
